package 股票买卖3;

import java.util.Scanner;

public class Main {
    static int N = 100010;
    static int[] p = new int[N];
    static int[] f = new int[N];//1~i
    static int[] g = new int[N];//i~n

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 1; i <= n; i++) {
            p[i] = in.nextInt();
        }
        for (int i = 2, minv = p[1]; i <= n; i++) {
            f[i] = Math.max(f[i - 1], p[i] - minv);
            minv = Math.min(minv, p[i]);
        }
        for (int i = n - 1, maxv = p[n]; i >= 1; i--) {
            g[i] = Math.max(g[i + 1], maxv - p[i]);
            maxv = Math.max(maxv, p[i]);
        }
        int res = 0;
        for (int i = 1; i <= n; i++) {
            res = Math.max(res, f[i] + g[i + 1]);
        }
        System.out.println(res);
    }
}
